import os

# 项目根目录
project_root = './'

# 初始化总行数
total_lines = 0

# 遍历项目根目录下的所有文件和文件夹
for root, dirs, files in os.walk(project_root):
    for file in files:
        # 只处理 Python 文件
        if file.endswith('.py'):
            file_path = os.path.join(root, file)
            try:
                # 打开文件并统计行数
                with open(file_path, 'r', encoding='utf-8') as f:
                    lines = f.readlines()
                    line_count = len(lines)
                    total_lines += line_count
                    print(f'{file_path}: {line_count} 行')
            except Exception as e:
                print(f'读取 {file_path} 时出错: {e}')

# 输出总行数
print(f'项目中所有 Python 文件的总行数: {total_lines}')